clc
clear

T = 1;
t = linspace(0, pi, 1000);
x = sawtooth(1*t,1);
figure(1)
plot(t, x, 'r')
grid on
hold on

k = 1:2:41;
fourier_x = 0;

for i = 1:1:20
    fourier_x = fourier_x + 2/(k(i)*pi) * sin(2*pi*k(i)*t/T);
end

plot(t, fourier_x, 'b')

R = 1;
C = 1;
w_0 = 1/(R*C);
H_1p_p = 1./(1+1i*k*R*C/T); % 修正为 1i
r_p = abs(H_1p_p); % 修正变量名
theta_p = angle(H_1p_p); % 修正变量名

fourier_x_lp = 0;

for i = 1:1:20
    fourier_x_lp = fourier_x_lp + 2*r_p(i)/(k(i)*pi) * sin(2*pi*k(i)/T*t + theta_p(i)); % 修正变量名和相位表达式
end

figure(2);
plot(t, x, 'r'); grid on; hold on;
plot(t, fourier_x_lp, 'b')